from inc.nwosu.greg.androidxmltestreporter import AndroidXmlTestReporter 
from datetime import datetime
import sys

from unittest import TestCase

class AndroidTestXmlReporterTest(TestCase):
   
   def setUp(self):
      self.rptr = AndroidXmlTestReporter()
      input_data_file = file('../../../resources/input-data.txt', 'r')
      self.input_data = input_data_file.read()
      input_data_file.close()
      expected_data_file = file('../../../resources/expected-data.xml', 'r')
      self.expected_data = expected_data_file.read()
      expected_data_file.close()

   def tearDown(self):
      pass
   
   def test_can_read_stdin(self):
     sys.stdout.write(self.input_data)
     actual_input = self.rptr.readreport()
     self.assertEqual(self.input_data, actual_input)
     
   def test_can_transform_report(self):
      actual_output = self.rptr.transformreport(self.input_data)
      print '*****THE ACTUAL OUTPUT IS',  actual_output 
      self.assertEqual(self.expected_data, actual_output)
      
   def test_can_transformtestsuite(self):
      testsuite_2tests_input_file = file('../../../resources/testsuite_2tests_input.txt', 'r')
      testsuite_2tests_input_data = testsuite_2tests_input_file.read()
      testsuite_2tests_input_file.close()
      testsuite_2tests_output_file = file('../../../resources/testsuite_2tests_output.xml', 'r')
      testsuite_2tests_output_data = testsuite_2tests_output_file.read()
      testsuite_2tests_output_file.close()
      self.assertEqual(testsuite_2tests_output_data, self.rptr.transformtestsuite(testsuite_2tests_input_data))
   
   def test_can_extract_classname_from_testsuite(self):
      testsuite_2tests_input_file = file('../../../resources/testsuite_2tests_input.txt', 'r')
      testsuite_2tests_input_data = testsuite_2tests_input_file.read()
      testsuite_2tests_input_file.close()
      actualclassname = self.rptr.getsuiteclass(testsuite_2tests_input_data)
      print 'actual class name' , actualclassname
      self.assertEquals('inc.nwosu.greg.test.view.PressButtonTest2', actualclassname)
      